%% init values %%


N = 128;
f = 2000;
f_sample = 8000;
amplitude = 5.0;
Ts = 1 /f_sample;
T = 1/f;


%% Sampling %%


f1 = [-N/2:((N/2)-1)]*(f_sample/N);
t = [0:(N-1)]*Ts;
frequency = 1./t;
x = zeros(1,N+1);
x = amplitude * sin(2 * pi * f * t);


%% FFT computing %%


X = fft(x);
Magnitude_X = abs(X);


%% Plotting %%


Real_part = real(fftshift(X));
Imaginary_part = imag(fftshift(X));


subplot(3,1,3);

    pl(1) = plot(f1,Real_part,'g')
    xlabel('frequency (Hz)')
    ylabel('X')
hold on
    pl(2) = plot(f1,Imaginary_part,'r')
    xlabel('frequency (Hz)')
    ylabel('X')
h1 = legend('eg1','eg2');    
    set(h1,'Location','NorthEast')
h2 = legend(pl,'real part of the FFT of x vs frequency','imaginary part of the FFT of x vs frequency');    
    set(h2,'Location','NorthEast')
hold off

subplot(3,1,1);
    plot(x)
    xlabel('time (s)')
    ylabel('x(t)')
    legend('sinewave x vs time')
    
 subplot(3,1,2);
    plot(f1,fftshift(Magnitude_X))
    xlabel('frequency (Hz)')
    ylabel('Magnitude')
    legend('Magnitude of the FFT of the sinewave x vs the frequency')
    
%  subplot(3,1,3);
%     plot(Magnitude_X)
%     xlabel('frequency')
%     ylabel('Magnitude')
%     legend('Magnitude of the FFT of the sinewave x vs the frequency')

%  subplot(3,1,3);
%     plot(Magnitude_X)
%     xlabel('frequency')
%     legend('Magnitude of the FFT of the sinewave x vs the frequency')
